package com.guosifan.controller;

import com.guosifan.entity.AllVO;
import com.guosifan.entity.User;
import com.guosifan.feign.UserClientFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/client/user")
public class UserClientController {

    @Autowired
    private UserClientFeign userClientFeign;

    @GetMapping("/findAll")
    @ResponseBody
    public  AllVO findAll(@RequestParam int page,@RequestParam int limit){
        List<User> allUser = userClientFeign.findAll((page - 1) * limit, limit);
        return new AllVO(0,"",userClientFeign.count(),allUser);
    }

    @PostMapping("/save")
    public String save(User user){
        user.setRegisterdate(new Date());
        userClientFeign.save(user);
        return "redirect:/user_manage.html";
    }

    @GetMapping("/deleteById/{id}")
    public String deleteById(@PathVariable("id") int id){
        System.out.println(id);
        userClientFeign.deleteById(id);
        return "redirect:/user_manage.html";
    }



}
